<template>
    <div>
        <div class="u-main">
          <div id="tab_menu">
            <ul class="u-tab clearfix">
              <li :class="{current:(model==1)}"><a href="javascript:void (0)" @click="changeModel(1)">身份认证</a></li>
              <li :class="{current:(model==2)}"><a href="javascript:void (0)" @click="changeModel(2)">手机认证</a></li>
              <li :class="{current:(model==3)}"><a href="javascript:void (0)" @click="changeModel(3)">邮箱认证</a></li>
            </ul>
          </div>
          <div id="tab_box">
            <div class="u-form-wrap" v-show="model==1">
              <div>
                <!--这是身份认证-->
                <ul class="u-tab clearfix">
                  <li class="current"><a>请设置xxx的身份证</a></li>
                </ul>
                <br /><br />
                <el-form ref="idcard" label-width="80px" size="30px">
                <el-form-item label="身份证号">
                  <i class="el-icon-picture-outline-round"></i>
                  <el-input style="width:505px;" v-model="IDcard"></el-input>
                </el-form-item>
                  <el-form-item label="真实姓名">
                    <i class="el-icon-picture-outline-round"></i>
                    <el-input style="width:505px;" v-model="realName"></el-input>
                    <br/><br/>
                    <!--身份证上传图片-->
                    <h1>上传身份证</h1>
                    <el-upload
                      action="https://jsonplaceholder.typicode.com/posts/"
                      list-type="picture-card"
                      :on-preview="handlePictureCardPreview"
                      :on-remove="handleRemove">
                      <i class="el-icon-plus"></i>
                    </el-upload>
                    <el-dialog :visible.sync="dialogVisible">
                      <img width="100%" :src="dialogImageUrl" alt="">
                    </el-dialog>
                    <br/>
                    <el-button type="primary" icon="el-icon-loading" @click="addIDcard">添加</el-button>
                  </el-form-item>
                </el-form>

              </div>
            </div>
            <div class="u-form-wrap" style="display: none;" v-show="model==2">
              <div>
                <!--这是手机认证-->
                <ul class="u-tab clearfix">
                  <li class="current"><a>请设置xxx的手机</a></li>
                </ul>
                <br /><br />
                <el-form ref="phone" label-width="80px" size="30px">
                  <el-form-item label="手机">
                    <i class="el-icon-picture-outline-round"></i>
                    <el-input v-model="myphonenum" style="width:200px;"  @blur="checkmobile"></el-input>
                    <el-button type="primary" icon="el-icon-loading" @click="sendPhoneCode">发送验证码</el-button>
                    <p style="color: red;font-size: 16px">{{phonemsg}}</p>
                  </el-form-item>
                  <el-form-item label="验证码">
                    <i class="el-icon-picture-outline-round"></i>
                    <el-input v-model="myphonecode" style="width:242px;"></el-input>
                    <el-button type="primary" icon="el-icon-loading" @click="changePhone">添加</el-button>
                  </el-form-item>
                </el-form>
              </div>
            </div>
            <div class="u-form-wrap" style="display: none;" v-show="model==3">
              <div>
                <!--这是邮箱认证-->
                <ul class="u-tab clearfix">
                  <li class="current"><a>请设置xxx的邮箱</a></li>
                </ul>
                <br /><br />
                <el-form ref="email" label-width="100px" size="30px">
                  <el-form-item label="邮箱">
                    <i class="el-icon-picture-outline-round"></i>
                    <el-input v-model="myemail" style="width:305px;" ></el-input>
                    <el-button type="primary" icon="el-icon-loading" @click="sendCode">发送</el-button>
                  </el-form-item>
                  <el-form-item label="邮件验证码">
                    <i class="el-icon-picture-outline-round"></i>
                    <el-input v-model="myemailcode" style="width:305px;"></el-input>
                    <el-button type="primary" icon="el-icon-loading" @click="changeEmail">添加</el-button>
                  </el-form-item>
                </el-form>
              </div>
            </div>
          </div>
        </div>
    </div>
</template>

<script>
    export default {
        name: "",
      data() {
        return {
          model:1,
          IDcard:"",
          realName:"",
          dialogImageUrl: '',
          dialogVisible: false,
          myphonenum:"",
          myphonecode:"",
          myemail:"",
          myemailcode:"",
          phonemsg:"",
          sendemailcode:"",
          mysendphonecode:""
        };
      },
      methods: {
          //添加身份证号
        addIDcard:function(){
          alert(this.IDcard)
          this.axios.post("/api/userHomePageController/addUsrIDCard",{
              card:this.IDcard,
            realName:this.realName
          }).then(data=>{
            if (data.data==0) {
              alert("身份认证成功")
            }
          })
        },
        //手机号的正则验证
        checkmobile:function () {
          if(!/^1[34578][0-9]{9}$/.test(this.myphonenum)){
            this.phonemsg="请输入正确的手机号！"
          }else{
            this.phonemsg=""

          }
        },

          //发送手机验证码
        sendPhoneCode:function(){
          alert(this.myphonenum)
          this.axios.get("/api/sms/sendSmsMsg/"+this.myphonenum,{}).then(data=>{
              console.log(data.data)
              alert("验证码发送成功！！！")
              this.mysendphonecode=data.data
          })

        },
        //修改手机
        changePhone:function(){
          if(this.myphonecode==this.mysendphonecode){
            this.axios.get("/api/userHomePageController/changephone/"+this.myphonenum).then(data=>{
              if(data.data==1000){
                alert("修改成功！！！")
              }
            })
          }else{
            alert("验证码不正确！！！")
          }
        },


          //发送邮箱验证码
        sendCode:function(){
          alert(this.myemail)
          this.axios.get("/api/sms/sendEmail/"+this.myemail,{}).then(data=>{
            console.log(data)
            this.sendemailcode=data.data
            alert("验证码发送成功，请查收！！！")
          })
        },
        //改变邮箱
        changeEmail:function(){
          if(this.sendemailcode==this.myemailcode){
            this.axios.get("/api/userHomePageController/changeEmail/"+this.myemail,{}).then(data=>{
              if(data.data==1){
                alert("邮箱激活成功")
              }
            })
          }else{
            alert("验证码不正确")
          }
        },
        handleRemove(file, fileList) {
          console.log(file, fileList);
        },
        handlePictureCardPreview(file) {
          this.dialogImageUrl = file.url;
          this.dialogVisible = true;
        },
        changeModel: function (i) {
          this.model=i
        }
      }
    }
</script>

<style scoped>
  @import  '../../assets/usercss/css/UserCSS.css';

</style>
